package com.springboot.demo.web;

import com.springboot.demo.entity.IncomeRecord;
import com.springboot.demo.service.IncomeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class IncomeController {

    @Autowired
    private IncomeRecordService incomeRecordService;

    @RequestMapping("/incomerecord")
    public String toIncome(Model model){

        List<IncomeRecord> list = incomeRecordService.listIncomeRecord();
        int total = 0;  //记录总的收入
        for(IncomeRecord e:list){
            total = total + e.getMoney();
        }
        model.addAttribute("record",list);
        model.addAttribute("totalmoney",total);
        return "income_record";
    }
}
